# == Schema Information
#
# Table name: operation_logs
#
#  id           :integer          not null, primary key
#  project_id   :string(255)
#  created_by   :integer
#  results      :text(65535)
#  success      :boolean
#  command_text :string(255)
#  created_at   :datetime         not null
#  updated_at   :datetime         not null
#  command_name :string(255)
#

class OperationLog < ApplicationRecord
  belongs_to :project
  belongs_to :user, class_name: 'User', foreign_key: :created_by
  after_create :send_notice

  def send_notice
    ActionCable.server.broadcast 'notice', {
        project_id: project_id,
        command_text: command_text,
        command_name: command_name,
        result: self.results.to_s.gsub("\n",'<br/>'),
        user: user.to_s,
        created_at: Time.now.label
    }
  end
end
